package com.sk.sourcecircle.activity.mine.act;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.zxing.WriterException;
import com.sk.sourcecircle.R;
import com.sk.sourcecircle.base.BaseActivity;
import com.sk.sourcecircle.view.StarBar;
import com.sk.sourcecircle.zxing.encoding.EncodingHandler;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by sk on 2018/1/7.
 */

public class PersonlCodeActivity extends BaseActivity {
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.group_image)
    ImageView groupImage;
    @BindView(R.id.group_name)
    TextView groupName;
    @BindView(R.id.des_star)
    StarBar desStar;
    @BindView(R.id.ll)
    LinearLayout ll;
    @BindView(R.id.img_code)
    ImageView imgCode;

    @Override
    protected int getContentView() {
        return R.layout.activity_personal_code;
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String name = getIntent().getStringExtra("name");
        String url  = getIntent().getStringExtra("url");
        int type = getIntent().getIntExtra("type",0);
        String codeString = getIntent().getStringExtra("string");

        Glide.with(mContext).load(url).into(groupImage);
        if(type == 0){
            tvTitle.setText("社群二维码");
        }else {

            tvTitle.setText("个人二维码");
        }
        groupName.setText(name);
        Bitmap mBitmap = null;
        try {
            mBitmap = EncodingHandler.createQRCode(codeString, 600);
            if (mBitmap != null) {
                Drawable drawable = new BitmapDrawable(mBitmap);
                imgCode.setBackground(drawable);
            }
        } catch (WriterException e) {
            e.printStackTrace();
        }


    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }
}
